package com.snailct.bpp.service.core.reader;

import com.snailct.bpp.service.core.definition.DefaultServiceDefinition;
import com.snailct.bpp.service.core.definition.ServiceDefinition;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Created by huangxa on 2016/7/14.
 */
public class DocDefinitionReader {
    public ServiceDefinition parseDoc(Document doc){
        ServiceDefinition serviceDefinition = new DefaultServiceDefinition();
        Element root = doc.getDocumentElement();
        NodeList nodeList = root.getChildNodes();
        for(int i=0;i<nodeList.getLength();i++){
            Node node = nodeList.item(i);
            if(node.getNodeName().equals("header")){
                NodeList headersNodes = node.getChildNodes();
                for(int j=0;j<headersNodes.getLength();j++){
                    Node reqMeta = headersNodes.item(j);
                    if(reqMeta.getNodeName().equals("serviceId")){
                        serviceDefinition.setServiceId(reqMeta.getTextContent());
                    }
                }

            }
        }
        return serviceDefinition;
    }


}
